<%@page import="mail.MailBean"%>
<%@page import="javax.activation.DataSource"%>
<%@page import="javax.activation.DataHandler"%>
<%@ page import="java.util.*,javax.mail.*, javax.mail.internet.*" %>

<%
 String name = request.getParameter("name"); 
 String from = request.getParameter("from"); 
 String subject = request.getParameter("betreff"); 
 String mesg = request.getParameter("nachricht"); 
 
 String host = "smtp.mail.yahoo.de";
 String user = "selcuk.imal@yahoo.de";
 String pass = "3283053";

 String success="false";
 // E-Mail settings
 String to = "selcuk.imal@yahoo.de";

 boolean sessionDebug = false;
 Properties props = System.getProperties();
 props.put("mail.host", host);
 props.put("mail.transport.protocol", "smtp");

 Session mailSession = Session.getDefaultInstance(props, null);
 mailSession.setDebug(sessionDebug);

 // Create message to send
 Message msg = new MimeMessage(mailSession);
 msg.setFrom(new InternetAddress(from));
 InternetAddress[] address = {new InternetAddress(to)};
 msg.setRecipients(Message.RecipientType.TO, address);
 msg.setSubject(subject);
 msg.setSentDate(new Date());
 String html = "<html><head><title>" +  
		 msg.getSubject() +  
         "</title></head><body>" 
         +"<div>" +"<b>Von: </b>" +name+  "</div>"
         +"<br>"
         +"<div>" +"<b>Nachricht: </b> <br>"+mesg.replaceAll("\n","<br>")+  "</div>"
         +"<br> <br> <br> <br>"
         +"<div style='font-style:italic; font-size: 11pt; color:gray;'> Dies ist eine von www.juelch-lack.de automatisch generierte Mail! </div>"
         +"</body></html>";  

msg.setDataHandler(new DataHandler(new MailBean(html)));//instead of simpleMessage.setText(yourText)  

 // Send message
 Transport transport = mailSession.getTransport("smtp");
 transport.connect(host, user, pass);
 try{
	 transport.sendMessage(msg, msg.getAllRecipients());
	 transport.close();
	 success="true";
	 name = ""; 
	 from = ""; 
	 subject = ""; 
	 mesg = ""; 
	 //response.sendRedirect("kontakt.jsp"); 
	// request.setAttribute("success", success);
 }catch (Exception e){
	// request.setAttribute("success", success);
 }

%>
 <jsp:forward page="kontakt.html" >
 <jsp:param name="success" value="<%=success%>"/>
  <jsp:param name="name" value="<%=name%>"/>
   <jsp:param name="from" value="<%=from%>"/>
    <jsp:param name="subject" value="<%=subject%>"/>
     <jsp:param name="mesg" value="<%=mesg%>"/>
</jsp:forward>
